package com.meida.module.user.provider.service.impl;


import com.meida.common.mybatis.base.service.impl.BaseServiceImpl;
import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.model.ListModel;
import com.meida.common.mybatis.model.PageModel;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.model.SaveModel;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.mybatis.query.CriteriaSave;
import com.meida.common.security.OpenHelper;
import com.meida.module.user.client.entity.AppDept;
import com.meida.module.user.provider.mapper.AppDeptMapper;
import com.meida.module.user.provider.service.AppDeptService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 部门 实现类
 *
 * @author flyme
 * @date 2019-07-05
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AppDeptServiceImpl extends BaseServiceImpl<AppDeptMapper, AppDept> implements AppDeptService {

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody listEntityMap(ListModel model) {
        CriteriaQuery<EntityMap> cq = new CriteriaQuery(model, AppDept.class);
        cq.select(AppDept.class, "*");
        return baseList(cq);
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody pageList(PageModel model) {
        CriteriaQuery cq = new CriteriaQuery(model, AppDept.class);
        cq.select(AppDept.class, "*");
        return basePageList(cq);
    }


    @Override
    public ResultBody add(SaveModel model) {
        CriteriaSave cs = new CriteriaSave(model, AppDept.class);
        Long companyId = OpenHelper.getCompanyId();
        cs.put("companyId", companyId);
        return baseAdd(cs,cs.getEntity(AppDept.class));
    }


}
